// Find all possible words from an input string.
// Please note that it may take some time to print out the words if they are long.
// By Ben 22:01 18/10/2018
#include <string>
#include <iostream>
#include <vector>
using namespace std;

vector<string>items;

void getWords(string str, string word) {
	int i = 0;
	string s0 = "";

	//Check if the word is already in the vector.
	if (std::find(items.begin(), items.end(), word) != items.end()){

	}
	else{
		//If length if more than zero add to vector.
		if (word.length()){
			//Add to vector
			items.push_back(word);
		}
	}

	while (i < str.length()){
		//Erase 1 letter frim str
		s0 = string(str).erase(i, 1);
		//Recall this procedure
		getWords(s0, word + str[i]);
		//INC counter
		i++;
	}
}

int main(int argc, char **argv) {

	string str = "test";
	getWords(str, "");

	//Display words found in the vector
	for (int i = 0; i < items.size(); i++){
		//Output word
		std::cout << items[i] << endl;
	}
	items.clear();

	system("pause");
	return 0;
}